﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class shop_ShopSiteConfig_BaseInfo : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindData();            
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

        //RequestCompetences = Competences.BuildCompetencesList(Competences.);//页面权限

        base.OnLoad(e);
    }

    #endregion

    protected void btnSave_Click(object sender, EventArgs e)
    {
        DAL.Tables.tbl_Shop Shop = new DAL.Tables.tbl_Shop();
        
        Shop.SiteTelephone.Value = this.txtTelephone.Text;
        Shop.SiteTitle.Value = this.txtSiteTitle.Text;
        Shop.Mobile.Value = this.txtMobile.Text;
        //Shop.SiteTelephone.Value = "";
        Shop.Email.Value = this.txtEmail.Text;
        Shop.PostCode.Value = this.txtPostCode.Text;
        Shop.Address.Value = this.txtAddress.Text;
        Shop.SiteURL.Value = this.txtSiteURL.Text;
        Shop.ShopName.Value = this.txtShopName.Text;
        Shop.SiteQQ.Value = this.txtSiteQQ.Text;
        Shop.CopyRightInfo.Value = this.txtCopyRightInfo.Text;
        Shop.ICPCert.Value = this.txtICPCert.Text;
        Shop.SiteCnzz.Value = this.tbSiteCnzz.Text;
        Shop.SiteScript.Value = this.tbSiteScript.Text;
        Shop.SiteService.Value = this.tbSiteService.Text;
        Shop.QQ1.Value = this.tbQQ1.Text;
        Shop.QQ2.Value = this.tbQQ2.Text;

        if (Shop.Update("ID=" + _Customer.ShopID) > 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "修改成功");
        }
        else
        {
            Shove._Web.JavaScript.Alert(this.Page, "修改失败");
        }

        BindData();
    }

    protected void btnEnterSite_Click(object sender, EventArgs e)
    {
        DataTable dt = new DAL.Tables.tbl_Shop().Open("", "[ID]=" + _Customer.ShopID, "");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读取错误", "ShopSiteConfig_BaseInfo");

            return;
        }
        
        int SiteStatus = Shove._Convert.StrToInt(dt.Rows[0]["SiteStatus"].ToString(), 0);
        if( SiteStatus == 1) //0 正常使用 1 暂停使用
        {
            //Shove._Web.Session.SetSession(Shove._Web.WebConfig.GetAppSettingsString("SystemPreFix") + "Manager", Shove._Security.Encrypt.EncryptString(PublicFunction.GetCallCert(), manager));
            Response.Write("<script>window.open('http://" + dt.Rows[0]["SiteURL"].ToString() + "/Default.aspx');</script>");
        }
        else
        {
            Shove._Web.JavaScript.Alert(this.Page, "您的网店暂未开通，请联系您的上级！");

            return;
        }
    }

    private void BindData()
    {
        DataTable dt = new DAL.Tables.tbl_Shop().Open("", "ID=" + _Customer.ShopID, "");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "暂无您需要查询的数据", "ShopSiteConfig_BaseInfo");

            return;
        }

        if (dt.Rows.Count > 0)
        {            
            this.txtTelephone.Text = dt.Rows[0]["SiteTelephone"].ToString();            
            this.txtMobile.Text = dt.Rows[0]["Mobile"].ToString();
            this.txtEmail.Text = dt.Rows[0]["Email"].ToString();
            this.txtPostCode.Text = dt.Rows[0]["PostCode"].ToString();
            this.txtAddress.Text = dt.Rows[0]["Address"].ToString();
            this.txtSiteURL.Text = dt.Rows[0]["SiteURL"].ToString();
            this.txtSiteTitle.Text = dt.Rows[0]["SiteTitle"].ToString();
            this.txtShopName.Text = dt.Rows[0]["ShopName"].ToString();
            this.txtSiteQQ.Text = dt.Rows[0]["SiteQQ"].ToString();
            this.txtCopyRightInfo.Text = dt.Rows[0]["CopyRightInfo"].ToString();
            this.txtICPCert.Text = dt.Rows[0]["ICPCert"].ToString();
            this.tbSiteCnzz.Text = dt.Rows[0]["SiteCnzz"].ToString();
            this.tbSiteScript.Text = dt.Rows[0]["SiteScript"].ToString();
            this.tbSiteService.Text = dt.Rows[0]["SiteService"].ToString();
            this.tbQQ1.Text = dt.Rows[0]["QQ1"].ToString();
            this.tbQQ2.Text = dt.Rows[0]["QQ2"].ToString();
        }
    }

}
